﻿using Morus;
using System;

namespace KAKA.Domain
{
    public partial class Event : IAggregateRoot
    {
        public static Event Create()
        {
            return new Event
            {
                Id = Guid.NewGuid(),
                CreateAt = DateTime.Now,
                Status = EventStatus.Signing | EventStatus.Hidden,
                Visits = 0,
            };
        }

        public bool IsSigning
        {
            get
            {
                return (Status & EventStatus.Signing) == EventStatus.Signing;
            }
        }

        public bool IsClosed
        {
            get
            {
                return (Status & EventStatus.Closed) == EventStatus.Closed;
            }
        }

        public bool IsHidden
        {
            get
            {
                return (Status & EventStatus.Hidden) == EventStatus.Hidden;
            }
        }

        public void Activate()
        {
            Status = (Status ^ EventStatus.Closed) | EventStatus.Signing;
        }

        public void Close()
        {
            Status = (Status ^ EventStatus.Signing) | EventStatus.Closed;
        }

        public void Hide()
        {
            Status = Status | EventStatus.Hidden;
        }

        public void Show()
        {
            Status = Status ^ EventStatus.Hidden;
        }

        public void Delete()
        {
            Status = Status | EventStatus.Deleted;
        }

        public void SignUp(Member member)
        {
            Slates.Add(new Slate
            {
                Event = this,
                CreateAt = DateTime.Now,
                Id = Guid.NewGuid(),
                Member = member,
                Paid = false,
                Charge = this.Charge,
            });
        }
    }
}
